<?php

namespace Iaem\HomeBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Iaem\UserBundle\Entity\User;

/**
 * Vote
 *
 * @ORM\Table(name="votes")
 * @ORM\Entity(repositoryClass="Iaem\HomeBundle\Entity\VoteRepository")
 */
class Vote
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var integer
     *
     * @ORM\ManyToOne(targetEntity="Iaem\UserBundle\Entity\User", inversedBy="votes")
     * @ORM\JoinColumn(name="userId", referencedColumnName="id")
     */
    private $user;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="whenVoted", type="datetime")
     */
    private $whenVoted;

    function __construct()
    {
        $this->whenVoted = new \DateTime('now');
    }

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set userId
     *
     * @param \Iaem\UserBundle\Entity\User $user
     * @return Vote
     */
    public function setUser(User $user)
    {
        $user->addVote($this);
        $this->user = $user;

        return $this;
    }

    /**
     * Get userId
     *
     * @return integer 
     */
    public function getUser()
    {
        return $this->user;
    }

    /**
     * Set whenVoted
     *
     * @param \DateTime $whenVoted
     * @return Vote
     */
    public function setWhenVoted($whenVoted)
    {
        $this->whenVoted = $whenVoted;

        return $this;
    }

    /**
     * Get whenVoted
     *
     * @return \DateTime 
     */
    public function getWhenVoted()
    {
        return $this->whenVoted;
    }
}
